// 多语言
import { createI18n } from 'vue-i18n'
import deepmerge from 'deepmerge'
import enUS from "./lang/en-US";
import zhCN from "./lang/zh-CN";
import zh from 'view-ui-plus/dist/locale/zh-CN';
import en from 'view-ui-plus/dist/locale/en-US';

export default function vueI18nInstance(locale) {
    if (!locale || typeof locale !== 'object') locale = {}
    const localeENUS = { ...enUS, ...en },
        localeZHCN = { ...zhCN, ...zh };
    return createI18n({
        legacy: true,
        locale: global.LANG || process.env.VUE_APP_LANG || "zh-CN",
        globalInjection: true,
        messages: {
            "en": deepmerge(localeENUS, locale['en'] || {}),
            "zh-CN": deepmerge(localeZHCN, locale['zh-CN'] || {}),
        },
        fallbackLocale: 'zh-CN',
        silentTranslationWarn: true,
        silentFallbackWarn: true
    })
}
